<!DOCTYPE html>
<html>

	<head>
		<meta charset="utf-8">
		<title>Layui</title>
		<meta name="renderer" content="webkit">
		<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
		<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
		<link rel="stylesheet" href="/techshine_war/layui/css/layui.css" media="all">
		<link rel="stylesheet" href="/techshine_war/bootstrap/bootstrap.css" media="all">
		<script src="/techshine_war/layui/layui.all.js" charset="utf-8"></script>
		<script src="/techshine_war/js/jquery.js"></script>
		<script src="/techshine_war/js/global.js" charset="utf-8"></script>
		<!--<script src="../release/wangEditor.js" charset="utf-8"></script>
		<script src="https://cdn.jsdelivr.net/npm/wangeditor@latest/dist/wangEditor.min.js"></script>-->
  <link href="https://unpkg.com/@wangeditor/editor@latest/dist/css/style.css" rel="stylesheet">
  <script src="https://unpkg.com/@wangeditor/editor@latest/dist/index.js"></script>
		<style>
			.layui-form-label {
				width: 120px;
			}
			
			.layui-input {
				width: 95%;
			}
			.editor-toolbar {
			  border: 1px solid #ccc;
			}
			
			.editor-text-area {
			  border: 1px solid #ccc;
			  border-top: 0;
			  height: 400px;
			}
		</style>
		<!-- 注意：如果你直接复制所有代码到本地，上述css路径需要改成你本地的 -->
	</head>

	<body>
		<form class="layui-form" id="edit-form" action="" style="margin: 20px;">

			

			<div class="layui-form-item">
				<label class="layui-form-label">姓名</label>
				<div class="layui-input-block">
					<input type="text" name="name" id="name" lay-verify="name" lay-reqtext="名称不能为空" placeholder="请输入" class="layui-input">
				</div>
			</div>
			<div class="layui-form-item">
				<label class="layui-form-label">单位</label>
				<div class="layui-input-block">
					<input type="number" name="comm" id="comm" lay-verify="comm" lay-reqtext="不能为空" value="1" placeholder="请输入名称" class="layui-input">
				</div>
			</div>
			<div class="layui-form-item">
				<label class="layui-form-label">电话</label>
				<div class="layui-input-block">
					<input type="number" name="phone" id="phone" lay-verify="phone" lay-reqtext="不能为空" value="1" placeholder="请输入名称" class="layui-input">
				</div>
			</div>
			<div class="layui-form-item">
				<label class="layui-form-label">邮箱</label>
				<div class="layui-input-block">
					<input type="number" name="email" id="email" lay-verify="email" lay-reqtext="不能为空" value="1" placeholder="请输入名称" class="layui-input">
				</div>
			</div>
			<div id="htmlvaldiv">
				<label class="layui-form-label">内容</label>
				<div class="layui-input-block" style="text-align: center;">
 					<textarea id="cont" name="cont" class="layui-input" ></textarea>			
				<div>
				
				
			</div>
			<div style="text-align: center;">
				<input type="hidden" id="id" name="id" value="" />
				<button type="button" class="layui-btn layui-btn-primary" onclick="closePage()">关闭</button>
			</div>

		</form>
		
		<script>
			//Demo
			var id = getQueryString("id");

			var form;
			var submiting = false;
			layui.use(['layer', 'form'], function() {
				var layedit = layui.layedit;
				
				form = layui.form;
				initData();
				
				//自定义验证规则
				//监听提交
				form.on('submit(formDemo)', function(data) {
					if(submiting) {
						return false;
					}
					
					$("#htmlval").val(editor.getHtml());
					var data = $("form").serializeArray();
					console.info(JSON.stringify(data.field))
					$.ajax({
						type: "post",
						url: '/techshine_war/msg/insert',
						async: false,
						data: data,
						success: function(res) {
							submiting = true;
							parent.reload();
							closePage();
						}
					});
					return false;
				});
				form.on('select(menutype)', function(data) {
					var sval = data.value;
					if(sval == '1') {
						$("#htmlvaldiv").show()
					} else {
						$("#htmlvaldiv").hide()
					}
					form.render(); //更新全部
					form.render('select');
				});
			});

			function initData() {
				if(id != null && id.length > 0) {
					$.ajax({
						type: "get",
						url: '/techshine_war/msg/queryByKey?id=' + id,
						async: false,
						success: function(res) {
							echoEdit(res.result);
						}
					});
				}
			}
			var editor ;
		</script>
	</body>

</html>